<?php
/**
 * 后台用户控制器
 * @author yupoxiong<i@yufuping.com>
 */

namespace app\admin\controller;
use app\admin\model\OtaCon;
use think\Request;
use app\admin\model\OtaGroup;

class OtaConController extends Controller
{

    //列表
    public function index(Request $request, OtaCon $model, OtaGroup $otaGroup)
    {

        $param = $request->param();
        if ($this->user->is_admin == 1) {
            $data = $model->scope('where', $param)
                ->paginate($this->admin['per_page'], false, ['query' => $request->get()]);
        }else{
            $data = $model->scope('where', $param)
                ->where(['con_account'=>$this->user->account])
                ->paginate($this->admin['per_page'], false, ['query' => $request->get()]);
        }

        $page = $data->render();
        foreach ($data as $k=>$d){
            $ota_group = $otaGroup->where(['id'=>$d['con_group']])->order('id','desc')->limit(1)->find();
            $data[$k]['group_name'] = $ota_group['group_name'];
        }

        //关键词，排序等赋值
        $this->assign($request->get());

        $this->assign([
            'data'  => $data,
            'page'  => $page,
            'total' => $data->total(),
        ]);
        return $this->fetch();
    }

}
